﻿using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace delete.Common.Adapter
{
    internal class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
    {
        public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        protected override void Adapt(IRegion region, StackPanel regionTarget)//往stackpanel中动态的添加控件的时候
        {
            region.Views.CollectionChanged += (s, e) =>
              {
                  if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)//，事件一旦触发检测到是新增进来的
                  {
                      foreach (FrameworkElement item in e.NewItems)
                      {
                          regionTarget.Children.Add(item);//就会里面不停的追加
                      }
                  }
              };
        }

        protected override IRegion CreateRegion()
        {
            return new Region();
        }
    }
}
